package com.zyh.alpacaSse.config;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;

import java.util.Base64;

/**
 * @Classname AlpacaConfig
 * @Description TODO()
 * @Date 2025-09-03 22:45
 * @Created by 86177
 */
@Configuration
public class AlpacaConfig {

    @Bean
    @ConfigurationProperties("alpaca.sse")
    public AlpacaSseProperties alpacaSseProperties() {
        return new AlpacaSseProperties();
    }

    @Bean
    public WebClient webClient(AlpacaSseProperties properties) {
        return WebClient.builder()
                .baseUrl(properties.getUrl())
                .defaultHeader("accept", "text/event-stream")
                .defaultHeader("Authorization", "Basic " +
                        Base64.getEncoder().encodeToString(
                                (properties.getApiKey() + ":" + properties.getApiSecret()).getBytes()))
                .build();
    }
}
